<?php
require_once dirname(dirname(dirname(__FILE__))).'/d3pipes/joints/D3pipesBlockAbstract.class.php' ;

class D3pipesBlockLinkslistSubstance extends D3pipesBlockAbstract {

	var $target_dirname = '';
	var $trustdirname   = 'links';

	function init()
	{
		// parse and check option for this class
		$params = array_map('trim', explode('|', $this->option));
		if (empty($params[0])) {
			$this->errors[] = _MD_D3PIPES_ERR_INVALIDDIRNAMEINBLOCK ."\n($this->pipe_id)" ;
			return FALSE ;
		}
		$this->target_dirname = preg_replace('/[^0-9a-zA-Z_-]/', '', $params[0]);

		// configurations
		$this->func_file = XOOPS_ROOT_PATH.'/modules/'.$this->target_dirname.'/blocks/blocks.php';
		$this->func_name = 'b_links_top_show';
		$this->block_options = array(
			'disable_renderer' => TRUE,
			0 => $this->target_dirname ,                      // mydirname
			1 => 0,                                           // order
			2 => empty($params[2]) ? 10 : intval($params[2]), // linknum
			3 => empty($params[3]) ? 25 : intval($params[3]), // length
			4 => empty($params[4]) ? 0  : 1,                  // screenshot
			5 => empty($params[5]) ? 0  : 1,                  // table or list
			6 => empty($params[6]) ? 1  : intval($params[6]), // cols number
			7 => empty($params[7]) ? 0  : intval($params[7]), // mobile
			8 => empty($params[8]) ? 0  : intval($params[8]), // adult
			9 => empty($params[9]) ? '' : trim( $params[9]),  // category
		) ;

		return TRUE;
	}

	function reassign($links)
	{
		$entries = array() ;
		foreach ($links as $link) {
			$entry = array(
				'pubtime'  => $link['date'] , 
				'link'     => str_replace('&amp;', '&', $link['link_url']),
				'headline' => $this->unhtmlspecialchars($link['title']),
			) ;
			$entry['fingerprint'] = $entry['link'] ;
			$entries[] = $entry ;
		}

		return $entries;
	}

}
